﻿CREATE OR REPLACE FUNCTION loop_f() RETURNS void AS $$
BEGIN
	FOR i IN 1 .. 1000 LOOP
		PERFORM * FROM Customers INNER JOIN Orders Using ("CustomerID")
			WHERE "CustomerID" = 'QUEEN' ORDER BY "ContactName";
	END LOOP;
END;
$$ LANGUAGE plpgsql;

SELECT * FROM Customers INNER JOIN Orders Using ("CustomerID")
	WHERE "CustomerID" = 'QUEEN' ORDER BY "ContactName";
SELECT loop_f();

DROP INDEX IF EXISTS customers_id_i;
CREATE INDEX customers_id_i ON Customers ("CustomerID");
DROP INDEX IF EXISTS customers_id_i;
DROP INDEX IF EXISTS orders_cid_i;
CREATE INDEX orders_cid_i ON Orders ("CustomerID");
DROP INDEX IF EXISTS orders_cid_i;

DROP INDEX IF EXISTS invisible;
